-- ========================================================
-- @File	: app.lua
-- @Brief	: 程序入口
-- @Author	: Leo Zhao
-- @Date	: 2016-05-05
-- ========================================================
xpcall(function()
	require('core.template');
	require('core.common');
	require('core.cookie');
	require('core.session');
	require('core.model');
	require('core.error');
	require('core.controller');
	require('core.router');
	require('core.json');
end, function(e)
	require('core.error');
	error_handler.fatal(e);
end);

function run()
	xpcall(function()
		_GET	= urlparam(_GET_ORG);
		_POST	= urlparam(_POST_ORG);
		_CONF	= dofile('app/config.lua');

		cookie.open();
		session.start();
		router.dispatch();
	end, function(err)
		if _REDIRECT then return end;
		error_handler.fatal(err);
	end)
end

run();
flush();
session.save();
